<?php  
class ControllerCommonHome extends Controller {
	public function index() {
		$this->language->load('common/home');
		
		$this->document->title = $this->config->get('config_title');
		$this->document->description = $this->config->get('config_meta_description');
		
		$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
		
		/**********************/
		$this->load->model('news/news');
		$content = $this->model_news_news->getArticleById(5);
		$this->data['content'] = array();
        if($content){	          
            $this->load->model('tool/seo_url');		
			$this->load->model('tool/image');            
            //$title = $content['name'];   
			$image = $content['image'] ? $this->model_tool_image->resize($content['image'], 122, 75) : null; 				
                $desc_info = html_entity_decode($content['description']);        
                if(stripos($desc_info, '<hr />') > 0){
                    $description = explode('<hr />', $desc_info);              
                    $description = strip_tags($description[0], '<a>') . '...';
                }
                else{        
                    $description = (strlen($desc_info) > 200) ? (mb_substr(strip_tags($desc_info), 0, 300) . ' ...') : html_entity_decode($content['description']);    
                }
                                
                $this->data['content'] = array(
                    'title'         => $content['name'],    
					'image'         => $image,					
                    'text'          => $description,
                    'readmore'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/list/welcome&content_id=5'),                    
                );           
        }  
		
		/*********************/
		
		/**********************/
		          
        $contents = $this->model_news_news->getAllarticleNewst();

        $this->data['contents'] = array();
        if($contents){	
            $this->load->model('tool/image');
            $this->load->model('tool/seo_url');
            
            foreach($contents as $item){                
                $title = $item['name'];               
                
                $image = $item['image'] ? $this->model_tool_image->resize($item['image'], 122, 75) : null; 
                
                $desc_info = html_entity_decode($item['description']);        
                if(stripos($desc_info, '<hr />')){
                    $description = explode('<hr />', $desc_info);              
                    $description = strip_tags($description[0], '<a>') . '...';
                }
                else{        
                    $description = (strlen($desc_info) > 100) ? (mb_substr(strip_tags($desc_info), 0, 160) . ' ...') : html_entity_decode($item['description']);    
                }
                                
                $this->data['contents'][] = array(
                    'title1'         => $item['name'],                  
                    'image1'         => $image,
                    'text1'          => $description,
                    'readmore1'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=news/list&content_id=' . $item['content_id']),                    
                );           
            }            
            
            
        }
		
		/*********************/
		$this->load->model('setting/store');
		
		if (!$this->config->get('config_store_id')) {
			$this->data['welcome'] = html_entity_decode($this->config->get('config_description_' . $this->config->get('config_language_id')), ENT_QUOTES, 'UTF-8');
		} else {
			$store_info = $this->model_setting_store->getStore($this->config->get('config_store_id'));
			
			if ($store_info) {
				$this->data['welcome'] = html_entity_decode($store_info['description'], ENT_QUOTES, 'UTF-8');
			} else {
				$this->data['welcome'] = '';
			}
		}
						
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/home.tpl';
		} else {
			$this->template = 'default/template/common/home.tpl';
		}
		
		$this->children = array(
			'common/column_right',
			'common/column_left',
			'common/footer',
			'common/header'
		);
		
		$this->load->model('checkout/extension');
		
		$module_data = $this->model_checkout_extension->getExtensionsByPosition('module', 'home');
		
		$this->data['modules'] = $module_data;
		
		foreach ($module_data as $result) {
			$this->children[] = 'module/' . $result['code'];
		}
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
}
?>